import com.asiainfo.kbisheet.model.KbsModel;
import com.asiainfo.kbisheet.vo.UserColumnHiddenVO;
import com.asiainfo.kbisheet.vo.UserColumnSetVO;

import mx.collections.ArrayCollection;
import mx.controls.Alert;
import mx.controls.advancedDataGridClasses.AdvancedDataGridColumn;
import mx.core.FlexGlobals;
import mx.managers.PopUpManager;

[Bindable]
private var kbsModel:KbsModel = KbsModel.getInstance();

private var columnUUIDs:ArrayCollection;

private function handleCloseEvent():void {
	PopUpManager.removePopUp(this);				
}

/*重置设置（删除）*/
private function doReset():void {
	clearHiddenUUID(kbsModel.userSetColumns);
	treeSet.dataProvider = kbsModel.userSetColumns;
}

private function clearHiddenUUID(children:Array):void {
	for each(var userColumnSetVO:UserColumnSetVO in children){
		userColumnSetVO.visible = true;
		
		if(userColumnSetVO.children != null && userColumnSetVO.children.length > 0){
			clearHiddenUUID(userColumnSetVO.children);
		}
	}
}

/*保存设置*/
private function doSave():void {
	var userColumnHiddenVO:UserColumnHiddenVO = new UserColumnHiddenVO();
	columnUUIDs = new ArrayCollection();
	pushHiddenUUID(kbsModel.userSetColumns);
	
	userColumnHiddenVO.userId = kbsModel.userId;
	userColumnHiddenVO.sheetId = kbsModel.sid;
	userColumnHiddenVO.columnUUIDs = columnUUIDs;
	
	flexServiceRO.saveUserColumnSets(userColumnHiddenVO);
}

private function pushHiddenUUID(children:Array):void {
	for each(var userColumnSetVO:UserColumnSetVO in children){
		if(!userColumnSetVO.visible){
			columnUUIDs.addItem(userColumnSetVO.uuid);
		}
		
		if(userColumnSetVO.children != null && userColumnSetVO.children.length > 0){
			pushHiddenUUID(userColumnSetVO.children);
		}
	}
}

/*保存设置结果*/
private function saveUserColumnSetsResult():void {
	var result:Boolean = flexServiceRO.saveUserColumnSets.lastResult;
	kbsModel.updateHiddenColumnUUIDs(columnUUIDs);
	PopUpManager.removePopUp(this);
}

private function allExportResult():void{
	PopUpManager.removePopUp(this);
}